class MaxQueue {

    Queue<Integer> queue;
    Deque<Integer> maxQueue;
    public MaxQueue() {
        queue = new ArrayDeque<>();
        maxQueue = new LinkedList<>();
    }
    
    public int max_value() {
        if(maxQueue.isEmpty()) {
            return -1;
        }
        return maxQueue.peekFirst();
    }
    
    public void push_back(int value) {
        while(!maxQueue.isEmpty() && maxQueue.peekLast() < value) {
            maxQueue.pollLast();
        }
        maxQueue.offerLast(value);
        queue.offer(value);
    }
    
    public int pop_front() {
        if(queue.size() == 0) {
            return -1;
        }
        int a = queue.poll();
        if(a == maxQueue.peekFirst()) {
            maxQueue.pollFirst();
        }
        return a;
    }
}

/**
 * Your MaxQueue object will be instantiated and called as such:
 * MaxQueue obj = new MaxQueue();
 * int param_1 = obj.max_value();
 * obj.push_back(value);
 * int param_3 = obj.pop_front();
 */